package com.epalmpay.controller.channel.trade;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.dto.system.BaseOutDTO;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.dto.trade.MerchantSettedDetailOutDTO;
import com.epalmpay.dto.trade.MerchantSettedInDTO;
import com.epalmpay.dto.trade.MerchantSettedInfoOutDTO;
import com.epalmpay.dto.trade.MerchantSettedListOutDTO;
import com.epalmpay.dto.trade.SettedBaseInDTO;
import com.epalmpay.entity.Page;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.service.trade.ITradeService;
import com.epalmpay.status.Rescode;
import com.epalmpay.util.Tools;

@Controller
@RequestMapping(value = "/channel/merchantSet")
public class MerchantSettedController {
	  @Resource
	    private ITradeService tradeService;
	/**
	 * 结算记录
	 * 
	 * @param offlineRecordInDTO
	 * @param pageDTO
	 * @return
	 */
	@RequestMapping(value = "/settedRecordList")
	@ResponseBody
	public MerchantSettedListOutDTO settedRecordList(MerchantSettedInDTO merchantSettedInDTO, PageDTO pageDTO) {
		MerchantSettedListOutDTO merchantSettedListOutDTO = new MerchantSettedListOutDTO();
		try {
			Page page = Tools.pageEmtity(pageDTO);
			merchantSettedListOutDTO = tradeService.settedRecordList(merchantSettedInDTO, page);
			merchantSettedListOutDTO.setPage(page);
			merchantSettedListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return merchantSettedListOutDTO;

		} catch (ApplicationException ae) {
			merchantSettedListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		} catch (Exception e) {
			merchantSettedListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return merchantSettedListOutDTO;
	}

	/**
	 * 完成结算
	 * 
	 * @return
	 */
	@RequestMapping(value = "/finishSetted")
	@ResponseBody
	public BaseOutDTO finishSetted(SettedBaseInDTO settedBaseInDTO) {
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {
			boolean  result=tradeService.finishMerChantSetted(settedBaseInDTO);
			if(result){
				baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			}else{
				baseOutDTO.setErrorCode(Rescode.FAIL, "操作失败");
			}		
			return baseOutDTO;

		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		} catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	}

	/**
	 * 结算详情
	 * 
	 * @return
	 */
	@RequestMapping(value = "/settedInfo")
	@ResponseBody
	public MerchantSettedInfoOutDTO settedInfo(SettedBaseInDTO settedBaseInDTO, PageDTO pageDTO) {
		MerchantSettedInfoOutDTO merchantSettedInfoOutDTO = new MerchantSettedInfoOutDTO();
		try {
			Page page = Tools.pageEmtity(pageDTO);
			merchantSettedInfoOutDTO = tradeService.getMerchantSettedInfo(settedBaseInDTO,page);
			
			merchantSettedInfoOutDTO.setPage(page);
			merchantSettedInfoOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return merchantSettedInfoOutDTO;

		} catch (ApplicationException ae) {
			merchantSettedInfoOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		} catch (Exception e) {
			merchantSettedInfoOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return merchantSettedInfoOutDTO;
	}

	/**
	 * 显示钱包交易记录分页列表
	 * 
	 * @param offlineRecordInDTO
	 * @param pageDTO
	 * @return
	 */
	@RequestMapping(value = "/settedDetail")
	@ResponseBody
	public MerchantSettedDetailOutDTO settedDetail(SettedBaseInDTO settedBaseInDTO) {
		MerchantSettedDetailOutDTO merchantSettedDetaiOutDTO = new MerchantSettedDetailOutDTO();
		try {
			
			merchantSettedDetaiOutDTO = tradeService.merchantSettedDetai(settedBaseInDTO);
		
			merchantSettedDetaiOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return merchantSettedDetaiOutDTO;

		} catch (ApplicationException ae) {
			merchantSettedDetaiOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		} catch (Exception e) {
			merchantSettedDetaiOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return merchantSettedDetaiOutDTO;
	}

}
